<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
  
 </body>
</html>
<script>
	//将  div#demo.demo  转化成  <div id="demo" class="demo"></div>
	var str = 'p#abc.footer'; //  p#aa.header;
	
	var newStr = str.replace(/([a-z]+)#([a-z0-9]+)\.([a-z0-9]+)/g, function(match,$1,$2,$3){
		//得到  div demo header
		console.log(match); //
		console.log($1);
		console.log($2);
		console.log($3);
		return '<'+ $1 + ' id="'+ $2 +'" class="'+ $3 +'"></'+$1+'>';
	});
	console.log(newStr)


	//深入replace()
	var a = 'abc';
	//在replace里面正则加了小括号之后，分段获取值，这个括号里所匹配到的值会以参数形式传到函数
	var newA = a.replace(/(a)(b)(c)/g, function(match, $1, $2, $3){
		//关键返回值
		console.log(match);//abc
		console.log($1);//a
		console.log($2);//b
		console.log($3);//c
		return '小白';
	})
	console.log(newA);
</script>
